home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / C / copyfuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  53.0 KB  |  2,508 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    copyfuncs.c
  4.  *    
  5.  *   DESCRIPTION
  6.  *     Copy functions for Postgres tree nodes.
  7.  *
  8.  *   INTERFACE ROUTINES
  9.  *    lispCopy        - partial copy function for lisp structures
  10.  *    NodeCopy        - function to recursively copy a node 
  11.  *    CopyObject        - \ simpler interfaces to 
  12.  *    CopyObjectUsing        - /  NodeCopy()
  13.  *    _copyXXX        - copy function for class XXX
  14.  *
  15.  *   NOTES
  16.  *    These routines are intended for use during development, and should
  17.  *    be improved before we do a production version.  Right now, every node
  18.  *    we create ships around a pointer to the function that knows how to
  19.  *    copy it.
  20.  *
  21.  *   IDENTIFICATION
  22.  *    $Header: /private/postgres/src/lib/C/RCS/copyfuncs.c,v 1.40 1992/07/26 17:10:05 mer Exp $
  23.  * ----------------------------------------------------------------
  24.  */
  25.  
  26. /* ----------------
  27.  *    this list of header files taken from other node file headers.
  28.  * ----------------
  29.  */
  30. #include <stdio.h>
  31.  
  32. #include "tmp/postgres.h"
  33.  
  34. #include "access/heapam.h"
  35. #include "access/htup.h"
  36. #include "utils/fmgr.h"
  37. #include "utils/log.h"
  38. #include "storage/lmgr.h"
  39. #include "utils/palloc.h"
  40.  
  41. #include "nodes/execnodes.h"
  42. #include "nodes/nodes.h"
  43. #include "nodes/pg_lisp.h"
  44. #include "nodes/plannodes.h"
  45. #include "nodes/primnodes.h"
  46. #include "nodes/relation.h"
  47.  
  48. #include "catalog/syscache.h"
  49. #include "catalog/pg_type.h"
  50.  
  51. extern bool    _copyLispValue();
  52.  
  53. /* ----------------------------------------------------------------
  54.  *    lispCopy
  55.  *
  56.  *     This copy function is used to make copies of just the
  57.  *    "internal nodes" (lisp structures) but not copy "leaf"
  58.  *    nodes.  In simpler terms, the recursion stops at the
  59.  *    first non-lisp node type.  This function allocates
  60.  *    memory with palloc().
  61.  * ----------------------------------------------------------------
  62.  */
  63.  
  64. LispValue
  65. lispCopy(lispObject)
  66.      LispValue lispObject;
  67. {
  68.      LispValue newnode;
  69.      if (lispObject == LispNil)
  70.      return(LispNil);
  71.      
  72.      newnode = (LispValue) lispAlloc();
  73.      newnode->type = lispObject->type;
  74.      newnode->outFunc = lispObject->outFunc;
  75.      newnode->equalFunc = lispObject->equalFunc;
  76.      newnode->copyFunc = lispObject->copyFunc;
  77.      
  78.      switch (lispObject->type) {
  79.      case T_LispSymbol:
  80.       newnode->val.name = lispObject->val.name;
  81.       newnode->cdr = LispNil;
  82.       break;
  83.      case T_LispStr:
  84.       newnode->val.str = lispObject->val.str;
  85.       newnode->cdr = LispNil;
  86.       break;
  87.      case T_LispInt:
  88.       newnode->val.fixnum = lispObject->val.fixnum;
  89.       newnode->cdr = LispNil;
  90.       break;
  91.      case T_LispFloat:
  92.       newnode->val.flonum = lispObject->val.flonum;
  93.       newnode->cdr = LispNil;
  94.       break;
  95.      case T_LispVector:
  96.       newnode->val.veci = lispObject->val.veci;
  97.       newnode->cdr = LispNil;
  98.       break;
  99.      case T_LispList:
  100.       newnode->val.car = lispCopy(lispObject->val.car);
  101.       newnode->cdr = lispCopy(lispObject->cdr);
  102.       break;
  103.      default:
  104.       newnode = lispObject;
  105.      }
  106.      return (newnode);
  107. }
  108.  
  109. /* ----------------------------------------------------------------
  110.  *    NodeCopy
  111.  *    CopyObject
  112.  *    CopyObjectUsing
  113.  *
  114.  *    These functions provide support for copying complex
  115.  *    trees of all node types which supply simple copy functions
  116.  *    defined below.
  117.  * ----------------------------------------------------------------
  118.  */
  119.  
  120. /* ----------------
  121.  *    NodeCopy is a function which calls the node's own
  122.  *    copy function to copy the node using the specified allocation
  123.  *    function and update the value of the "to" pointer.
  124.  * ----------------
  125.  */
  126. bool
  127. NodeCopy(from, toP, alloc)
  128.     Node     from;
  129.     Node     *toP;
  130.     char *    (*alloc)();
  131. {
  132.     bool    (*copyfunc)();
  133.  
  134.     /* ----------------
  135.      *    if the "from" node is NULL, then just assign NULL to the 
  136.      *  "to" node. 
  137.      * ----------------
  138.      */
  139.     if (from == NULL) {
  140.     (*toP) = NULL;
  141.     return true;
  142.     }
  143.     
  144.     /* ----------------
  145.      *    if the copy function doesn't exist then we print
  146.      *  a warning and do a pointer assignment.
  147.      * ----------------
  148.      */
  149.     copyfunc = from->copyFunc;
  150.     if (copyfunc == NULL) {
  151.     elog(NOTICE,
  152.          "NodeCopy: NULL copy function (type: %d) -- doing ptr assign",
  153.          from->type);
  154.     (*toP) = from;
  155.     return true;
  156.     } else
  157.     return (*copyfunc)(from, toP, alloc);
  158. }
  159.  
  160. /* ----------------
  161.  *    CopyObject is a simpler top level interface
  162.  *    to the NodeCopy.  Given a pointer to
  163.  *    the root of a node tree, it returns a pointer to a copy
  164.  *    of the tree which was allocated with palloc.
  165.  * ----------------
  166.  */
  167. Node
  168. CopyObject(from)
  169.     Node from;
  170. {
  171.     Node copy;
  172.     
  173. #ifndef PALLOC_DEBUG
  174.     Pointer (*f)() = palloc;
  175. #else
  176.     Pointer (*f)() = palloc_debug;
  177. #endif PALLOC_DEBUG
  178.  
  179.     if (NodeCopy(from, ©, f) == true)
  180.     return copy;
  181.     else
  182.     return NULL;
  183. }
  184.  
  185. /* ----------------
  186.  *    CopyObjectUsing() is identical to CopyObject() but takes
  187.  *    a second parameter which is a pointer to the allocation
  188.  *    function to use in making the copy.
  189.  *
  190.  *    In particular, this function is needed in the parallel
  191.  *    executor code to place copies of query plans into shared
  192.  *    memory.
  193.  * ----------------
  194.  */
  195. Node
  196. CopyObjectUsing(from, alloc)
  197.     Node     from;
  198.     char *    (*alloc)();
  199. {
  200.     Node copy;
  201.  
  202.     if (alloc == NULL) {
  203.     elog(NOTICE, "CopyObjectUsing: alloc function is NULL!");
  204.     return NULL;
  205.     }
  206.     
  207.     if (NodeCopy(from, ©, alloc) == true)
  208.     return copy;
  209.     else
  210.     return NULL;
  211. }
  212.  
  213. /* ----------------------------------------------------------------
  214.  *    NodeCopy/CopyObject/CopyObjectUsing support functions
  215.  * ----------------------------------------------------------------
  216.  */
  217.  
  218. /* ----------------
  219.  *    Node_Copy
  220.  *
  221.  *    a macro to simplify calling of NodeCopy from within
  222.  *    the copy support routines:
  223.  *
  224.  *        if (NodeCopy(from->state, &(newnode->state), alloc) != true)
  225.  *           return false;
  226.  *
  227.  *    becomes
  228.  *
  229.  *        Node_Copy(from, newnode, alloc, state);
  230.  *
  231.  * ----------------
  232.  */
  233. #define Node_Copy(a, b, c, d) \
  234.     if (NodeCopy(((a)->d), &((b)->d), c) != true) { \
  235.        return false; \
  236.     } 
  237.  
  238. /* ----------------
  239.  *    COPY_CHECKARGS, COPY_CHECKNULL and COPY_NEW are macros used
  240.  *    to simplify all the _copy functions.  COPY_NEW_TYPE is exactly
  241.  *    like COPY_NEW, except that instead of returning 'false' on
  242.  *    failure, it returns the appropriate type of NULL.
  243.  * ----------------
  244.  */
  245. #ifndef PALLOC_DEBUG    
  246. #define COPYALLOC(x)    (*alloc)(x)
  247. #else
  248. #define COPYALLOC(x)    (alloc == palloc_debug ? palloc(x) : (*alloc)(x))
  249. #endif PALLOC_DEBUG
  250.  
  251. #define COPY_CHECKARGS() \
  252.     if (to == NULL || alloc == NULL) { \
  253.        return false; \
  254.     } 
  255.                       
  256. #define COPY_CHECKNULL() \
  257.     if (from == NULL) { \
  258.     (*to) = NULL; \
  259.     return true; \
  260.     } 
  261.  
  262. #define COPY_NEW(c) \
  263.     newnode = (c) COPYALLOC(classSize(c)); \
  264.     if (newnode == NULL) { \
  265.     return false; \
  266.     } 
  267.  
  268. #define COPY_NEW_TYPE(c) \
  269.     newnode = (c) COPYALLOC(classSize(c)); \
  270.     if (newnode == NULL) { \
  271.     return (c) NULL; \
  272.     }
  273.  
  274. /* ****************************************************************
  275.  *               nodes.h copy functions
  276.  * ****************************************************************
  277.  */
  278.  
  279. /* ----------------
  280.  *    CopyNodeFields
  281.  *
  282.  *    This function copies the fields of the Node node.  It is used by
  283.  *    all the copy functions for classes which inherit from Node.
  284.  * ----------------
  285.  */
  286. bool CopyNodeFields(from, newnode, alloc)
  287.     Node     from;
  288.     Node     newnode;
  289.     char *    (*alloc)();
  290. {
  291.     newnode->type = from->type;
  292.     newnode->outFunc = from->outFunc;
  293.     newnode->equalFunc = from->equalFunc;
  294.     newnode->copyFunc = from->copyFunc;
  295.     return true;
  296. }
  297.    
  298. /* ----------------
  299.  *    _copyNode
  300.  * ----------------
  301.  */
  302.         
  303. bool
  304. _copyNode(from, to, alloc)
  305.     Node    from;
  306.     Node    *to;
  307.     char *    (*alloc)();
  308. {
  309.     Node    newnode;
  310.  
  311.     COPY_CHECKARGS();
  312.     COPY_CHECKNULL();
  313.     COPY_NEW(Node);
  314.     
  315.     /* ----------------
  316.      *    copy the node
  317.      * ----------------
  318.      */
  319.     CopyNodeFields(from, newnode, alloc);
  320.     
  321.     (*to) = newnode;
  322.     return true;
  323. }
  324.  
  325. /* ****************************************************************
  326.  *             plannodes.h copy functions
  327.  * ****************************************************************
  328.  */
  329.  
  330. /* ----------------
  331.  *    CopyPlanFields
  332.  *
  333.  *    This function copies the fields of the Plan node.  It is used by
  334.  *    all the copy functions for classes which inherit from Plan.
  335.  * ----------------
  336.  */
  337. bool CopyPlanFields(from, newnode, alloc)
  338.     Plan     from;
  339.     Plan     newnode;
  340.     char *    (*alloc)();
  341. {
  342.     newnode->cost =         from->cost;
  343.     newnode->plan_size =     from->plan_size;
  344.     newnode->plan_width =     from->plan_width;
  345.     newnode->fragment =        from->fragment;
  346.     newnode->parallel =     from->parallel;
  347.     
  348.     Node_Copy(from, newnode, alloc, state);
  349.     Node_Copy(from, newnode, alloc, qptargetlist);
  350.     Node_Copy(from, newnode, alloc, qpqual);
  351.     Node_Copy(from, newnode, alloc, lefttree);
  352.     Node_Copy(from, newnode, alloc, righttree);
  353.     return true;
  354. }
  355.     
  356. /* ----------------
  357.  *    _copyPlan
  358.  * ----------------
  359.  */
  360. bool
  361. _copyPlan(from, to, alloc)
  362.     Plan    from;
  363.     Plan    *to;
  364.     char *    (*alloc)();
  365. {
  366.     Plan    newnode;
  367.  
  368.     COPY_CHECKARGS();
  369.     COPY_CHECKNULL();
  370.     COPY_NEW(Plan);
  371.     
  372.     /* ----------------
  373.      *    copy the node superclass fields
  374.      * ----------------
  375.      */
  376.     CopyNodeFields(from, newnode, alloc);
  377.     CopyPlanFields(from, newnode, alloc);
  378.     
  379.     (*to) = newnode;
  380.     return true;
  381. }
  382.  
  383.     
  384. /* ----------------
  385.  *    _copyExistential
  386.  * ----------------
  387.  */
  388. bool
  389. _copyExistential(from, to, alloc)
  390.     Existential    from;
  391.     Existential    *to;
  392.     char *    (*alloc)();
  393. {
  394.     Existential    newnode;
  395.  
  396.     COPY_CHECKARGS();
  397.     COPY_CHECKNULL();
  398.     COPY_NEW(Existential);
  399.     
  400.     /* ----------------
  401.      *    copy node superclass fields
  402.      * ----------------
  403.      */
  404.     CopyNodeFields(from, newnode, alloc);
  405.     CopyPlanFields(from, newnode, alloc);
  406.  
  407.     (*to) = newnode;
  408.     return true;
  409. }
  410.  
  411.     
  412. /* ----------------
  413.  *    _copyResult
  414.  * ----------------
  415.  */
  416. bool
  417. _copyResult(from, to, alloc)
  418.     Result    from;
  419.     Result    *to;
  420.     char *    (*alloc)();
  421. {
  422.     Result    newnode;
  423.  
  424.     COPY_CHECKARGS();
  425.     COPY_CHECKNULL();
  426.     COPY_NEW(Result);
  427.     
  428.     /* ----------------
  429.      *    copy node superclass fields
  430.      * ----------------
  431.      */
  432.     CopyNodeFields(from, newnode, alloc);
  433.     CopyPlanFields(from, newnode, alloc);
  434.  
  435.     /* ----------------
  436.      *    copy remainder of node 
  437.      * ----------------
  438.      */
  439.     Node_Copy(from, newnode, alloc, resrellevelqual);
  440.     Node_Copy(from, newnode, alloc, resconstantqual);
  441.     Node_Copy(from, newnode, alloc, resstate);
  442.         
  443.     (*to) = newnode;
  444.     return true;
  445. }
  446.     
  447. /* ----------------
  448.  *    _copyAppend
  449.  * ----------------
  450.  */
  451. bool
  452. _copyAppend(from, to, alloc)
  453.     Append    from;
  454.     Append    *to;
  455.     char *    (*alloc)();
  456. {
  457.     Append    newnode;
  458.  
  459.     COPY_CHECKARGS();
  460.     COPY_CHECKNULL();
  461.     COPY_NEW(Append);
  462.     
  463.     /* ----------------
  464.      *    copy node superclass fields
  465.      * ----------------
  466.      */
  467.     CopyNodeFields(from, newnode, alloc);
  468.     CopyPlanFields(from, newnode, alloc);
  469.  
  470.     /* ----------------
  471.      *    copy remainder of node 
  472.      * ----------------
  473.      */
  474.     Node_Copy(from, newnode, alloc, unionplans);
  475.     Node_Copy(from, newnode, alloc, unionrelid);
  476.     Node_Copy(from, newnode, alloc, unionrtentries);
  477.     Node_Copy(from, newnode, alloc, unionstate);
  478.         
  479.     (*to) = newnode;
  480.     return true;
  481. }
  482.  
  483.     
  484. /* ----------------
  485.  *    CopyScanFields
  486.  *
  487.  *    This function copies the fields of the Scan node.  It is used by
  488.  *    all the copy functions for classes which inherit from Scan.
  489.  * ----------------
  490.  */
  491. bool
  492. CopyScanFields(from, newnode, alloc)
  493.     Scan     from;
  494.     Scan     newnode;
  495.     char *    (*alloc)();
  496. {
  497.     newnode->scanrelid = from->scanrelid;
  498.     Node_Copy(from, newnode, alloc, scanstate);
  499.     return true;
  500. }
  501.  
  502. /* ----------------
  503.  *    CopyRelDescUsing is a function used by CopyScanTempFields.
  504.  *
  505.  *    Note: when this function changes, make sure to change the function
  506.  *    sizeofTmpRelDesc() in tcop/pfrag.c accordingly.
  507.  * ----------------
  508.  */
  509. Relation
  510. CopyRelDescUsing(reldesc, alloc)
  511.     Relation    reldesc;
  512.     char *    (*alloc)();
  513. {
  514.     int     len;
  515.     int     natts;
  516.     int     i;
  517.     Relation     newreldesc;
  518.  
  519.     natts =     reldesc->rd_rel->relnatts;
  520.     len =     sizeof *reldesc + (int)(natts - 1) * sizeof reldesc->rd_att;
  521.     
  522.     newreldesc = (Relation) COPYALLOC(len);
  523.     
  524.     newreldesc->rd_fd =     reldesc->rd_fd;
  525.     newreldesc->rd_refcnt =     reldesc->rd_refcnt;
  526.     newreldesc->rd_ismem =    reldesc->rd_ismem;
  527.     newreldesc->rd_am =     reldesc->rd_am;  /* YYY */
  528.     
  529.     newreldesc->rd_rel = (RelationTupleForm)
  530.     COPYALLOC(sizeof (RuleLock) + sizeof *reldesc->rd_rel);
  531.     *newreldesc->rd_rel = *reldesc->rd_rel;
  532.     
  533.     newreldesc->rd_id =     reldesc->rd_id;
  534.     
  535.     if (reldesc->lockInfo != NULL) {
  536.     newreldesc->lockInfo = (Pointer)
  537.         COPYALLOC(sizeof(LockInfoData));
  538.         *(LockInfo)(newreldesc->lockInfo) = *(LockInfo)(reldesc->lockInfo); 
  539.     }
  540.  
  541.     len = sizeof *reldesc->rd_att.data[0];
  542.     for (i = 0; i < natts; i++) {
  543.         newreldesc->rd_att.data[i] = (AttributeTupleForm)
  544.             COPYALLOC(len + sizeof (RuleLock));
  545.  
  546.         bcopy((char *)reldesc->rd_att.data[i],
  547.           (char *)newreldesc->rd_att.data[i],
  548.           len);
  549.         bzero((char *)(newreldesc->rd_att.data[i] + 1), sizeof (RuleLock));
  550.         newreldesc->rd_att.data[i]->attrelid =
  551.         reldesc->rd_att.data[i]->attrelid;
  552.     }
  553.     
  554.     return newreldesc;
  555. }
  556.  
  557. /* ----------------
  558.  *    copy a list of reldescs
  559.  * ----------------
  560.  */
  561. List
  562. copyRelDescsUsing(relDescs, alloc)
  563.     List    relDescs;
  564.     char *    (*alloc)();
  565. {
  566.     List newlist;
  567.  
  568.     if (lispNullp(relDescs))
  569.     return LispNil;
  570.     
  571.     newlist = (List) COPYALLOC(classSize(LispValue));
  572.     CopyNodeFields(relDescs, newlist, alloc);
  573.     newlist->val.car =     (LispValue) CopyRelDescUsing(CAR(relDescs), alloc);
  574.     newlist->cdr =     copyRelDescsUsing(CDR(relDescs), alloc);
  575.     return newlist;
  576. }
  577.  
  578.     
  579. /* ----------------
  580.  *    CopyScanTempFields
  581.  *
  582.  *    This function copies the fields of the ScanTemps node.  It is used by
  583.  *    all the copy functions for classes which inherit from Scan.
  584.  * ----------------
  585.  */
  586. bool CopyScanTempFields(from, newnode, alloc)
  587.     ScanTemps     from;
  588.     ScanTemps     newnode;
  589.     char *    (*alloc)();
  590. {
  591.     newnode->temprelDescs = copyRelDescsUsing(from->temprelDescs, alloc);
  592.     Node_Copy(from, newnode, alloc, scantempState);
  593.     return true;
  594. }
  595.     
  596. /* ----------------
  597.  *    _copyScan
  598.  * ----------------
  599.  */
  600. bool
  601. _copyScan(from, to, alloc)
  602.     Scan    from;
  603.     Scan    *to;
  604.     char *    (*alloc)();
  605. {
  606.     Scan    newnode;
  607.  
  608.     COPY_CHECKARGS();
  609.     COPY_CHECKNULL();
  610.     COPY_NEW(Scan);
  611.     
  612.     /* ----------------
  613.      *    copy node superclass fields
  614.      * ----------------
  615.      */
  616.     CopyNodeFields(from, newnode, alloc);
  617.     CopyPlanFields(from, newnode, alloc);
  618.     CopyScanFields(from, newnode, alloc);
  619.  
  620.     (*to) = newnode;
  621.     return true;
  622. }
  623.     
  624. /* ----------------
  625.  *    _copyScanTemp
  626.  * ----------------
  627.  */
  628. bool
  629. _copyScanTemps(from, to, alloc)
  630.     ScanTemps    from;
  631.     ScanTemps    *to;
  632.     char *    (*alloc)();
  633. {
  634.     ScanTemps    newnode;
  635.  
  636.     COPY_CHECKARGS();
  637.     COPY_CHECKNULL();
  638.     COPY_NEW(ScanTemps);
  639.     
  640.     /* ----------------
  641.      *    copy node superclass fields
  642.      * ----------------
  643.      */
  644.     CopyNodeFields(from, newnode, alloc);
  645.     CopyPlanFields(from, newnode, alloc);
  646.     CopyScanTempFields(from, newnode, alloc);
  647.  
  648.     (*to) = newnode;
  649.     return true;
  650. }
  651.     
  652. /* ----------------
  653.  *    _copySeqScan
  654.  * ----------------
  655.  */
  656. bool
  657. _copySeqScan(from, to, alloc)
  658.     SeqScan    from;
  659.     SeqScan    *to;
  660.     char *    (*alloc)();
  661. {
  662.     SeqScan    newnode;
  663.  
  664.     COPY_CHECKARGS();
  665.     COPY_CHECKNULL();
  666.     COPY_NEW(SeqScan);
  667.     
  668.     /* ----------------
  669.      *    copy node superclass fields
  670.      * ----------------
  671.      */
  672.     CopyNodeFields(from, newnode, alloc);
  673.     CopyPlanFields(from, newnode, alloc);
  674.     CopyScanFields(from, newnode, alloc);
  675.  
  676.     (*to) = newnode;
  677.     return true;
  678. }
  679.  
  680. /* ----------------
  681.  *    _copyIndexScan
  682.  * ----------------
  683.  */
  684. bool
  685. _copyIndexScan(from, to, alloc)
  686.     IndexScan    from;
  687.     IndexScan    *to;
  688.     char *    (*alloc)();
  689. {
  690.     IndexScan    newnode;
  691.  
  692.     COPY_CHECKARGS();
  693.     COPY_CHECKNULL();
  694.     COPY_NEW(IndexScan);
  695.     
  696.     /* ----------------
  697.      *    copy node superclass fields
  698.      * ----------------
  699.      */
  700.     CopyNodeFields(from, newnode, alloc);
  701.     CopyPlanFields(from, newnode, alloc);
  702.     CopyScanFields(from, newnode, alloc);
  703.  
  704.     /* ----------------
  705.      *    copy remainder of node 
  706.      * ----------------
  707.      */
  708.     Node_Copy(from, newnode, alloc, indxid);
  709.     Node_Copy(from, newnode, alloc, indxqual);
  710.     Node_Copy(from, newnode, alloc, indxstate);
  711.     
  712.     (*to) = newnode;
  713.     return true;
  714. }
  715.  
  716. /* ----------------
  717.  *      -copyJoinRuleInfo
  718.  * ----------------
  719.  */
  720. bool
  721. _copyJoinRuleInfo(from, to, alloc)
  722.     JoinRuleInfo        from;
  723.     JoinRuleInfo        *to;
  724.     char *              (*alloc)();
  725. {
  726.     JoinRuleInfo newnode;
  727.  
  728.     COPY_CHECKARGS();
  729.     COPY_CHECKNULL();
  730.     COPY_NEW(JoinRuleInfo);
  731.  
  732.     newnode->jri_operator =     from->jri_operator;
  733.     newnode->jri_inattrno =     from->jri_inattrno;
  734.     newnode->jri_outattrno =     from->jri_outattrno;
  735.     newnode->jri_lock =     from->jri_lock;
  736.     newnode->jri_ruleid =     from->jri_ruleid;
  737.     newnode->jri_stubid =     from->jri_stubid;
  738.     newnode->jri_stub =     from->jri_stub;
  739.  
  740.     (*to) = newnode;
  741.     return(true);
  742. }
  743.     
  744. /* ----------------
  745.  *    CopyJoinFields
  746.  *
  747.  *    This function copies the fields of the Join node.  It is used by
  748.  *    all the copy functions for classes which inherit from Join.
  749.  * ----------------
  750.  */
  751. bool CopyJoinFields(from, newnode, alloc)
  752.     Join     from;
  753.     Join     newnode;
  754.     char *    (*alloc)();
  755. {
  756.     Node_Copy(from, newnode, alloc, ruleinfo);
  757.     return true;
  758. }
  759.     
  760.  
  761. /* ----------------
  762.  *    _copyJoin
  763.  * ----------------
  764.  */
  765. bool
  766. _copyJoin(from, to, alloc)
  767.     Join    from;
  768.     Join    *to;
  769.     char *    (*alloc)();
  770. {
  771.     Join    newnode;
  772.  
  773.     COPY_CHECKARGS();
  774.     COPY_CHECKNULL();
  775.     COPY_NEW(Join);
  776.     
  777.     /* ----------------
  778.      *    copy node superclass fields
  779.      * ----------------
  780.      */
  781.     CopyNodeFields(from, newnode, alloc);
  782.     CopyPlanFields(from, newnode, alloc);
  783.     CopyJoinFields(from, newnode, alloc);
  784.  
  785.     (*to) = newnode;
  786.     return true;
  787. }
  788.     
  789.  
  790. /* ----------------
  791.  *    _copyNestLoop
  792.  * ----------------
  793.  */
  794. bool
  795. _copyNestLoop(from, to, alloc)
  796.     NestLoop    from;
  797.     NestLoop    *to;
  798.     char *    (*alloc)();
  799. {
  800.     NestLoop    newnode;
  801.  
  802.     COPY_CHECKARGS();
  803.     COPY_CHECKNULL();
  804.     COPY_NEW(NestLoop);
  805.     
  806.     /* ----------------
  807.      *    copy node superclass fields
  808.      * ----------------
  809.      */
  810.     CopyNodeFields(from, newnode, alloc);
  811.     CopyPlanFields(from, newnode, alloc);
  812.     CopyJoinFields(from, newnode, alloc);
  813.  
  814.     /* ----------------
  815.      *    copy remainder of node
  816.      * ----------------
  817.      */
  818.     Node_Copy(from, newnode, alloc, nlstate);
  819.     
  820.     (*to) = newnode;
  821.     return true;
  822. }
  823.  
  824.  
  825. /* ----------------
  826.  *    _copyMergeJoin
  827.  * ----------------
  828.  */
  829. bool
  830. _copyMergeJoin(from, to, alloc)
  831.     MergeJoin    from;
  832.     MergeJoin    *to;
  833.     char *    (*alloc)();
  834. {
  835.     MergeJoin    newnode;
  836.     LispValue    x, y;
  837.     List    newlist;
  838.  
  839.     COPY_CHECKARGS();
  840.     COPY_CHECKNULL();
  841.     COPY_NEW(MergeJoin);
  842.     
  843.     /* ----------------
  844.      *    copy node superclass fields
  845.      * ----------------
  846.      */
  847.     CopyNodeFields(from, newnode, alloc);
  848.     CopyPlanFields(from, newnode, alloc);
  849.     CopyJoinFields(from, newnode, alloc);
  850.  
  851.     /* ----------------
  852.      *    copy remainder of node
  853.      * ----------------
  854.      */
  855.     Node_Copy(from, newnode, alloc, mergeclauses);
  856.     
  857.     newnode->mergesortop = from->mergesortop;
  858.     newlist = LispNil;
  859.     foreach (x, from->mergerightorder) {
  860.     newlist = nappend1(newlist, CAR(x));
  861.     }
  862.     
  863.     newnode->mergerightorder = newlist;
  864.     newlist = LispNil;
  865.     foreach (x, from->mergeleftorder) {
  866.     newlist = nappend1(newlist, CAR(x));
  867.     }
  868.     
  869.     newnode->mergeleftorder = newlist;
  870.     Node_Copy(from, newnode, alloc, mergestate);
  871.     
  872.     (*to) = newnode;
  873.     return true;
  874. }
  875.     
  876.  
  877. /* ----------------
  878.  *    _copyHashJoin
  879.  * ----------------
  880.  */
  881. bool
  882. _copyHashJoin(from, to, alloc)
  883.     HashJoin    from;
  884.     HashJoin    *to;
  885.     char *    (*alloc)();
  886. {
  887.     HashJoin    newnode;
  888.  
  889.     COPY_CHECKARGS();
  890.     COPY_CHECKNULL();
  891.     COPY_NEW(HashJoin);
  892.     
  893.     /* ----------------
  894.      *    copy node superclass fields
  895.      * ----------------
  896.      */
  897.     CopyNodeFields(from, newnode, alloc);
  898.     CopyPlanFields(from, newnode, alloc);
  899.     CopyJoinFields(from, newnode, alloc);
  900.  
  901.     /* ----------------
  902.      *    copy remainder of node
  903.      * ----------------
  904.      */
  905.     Node_Copy(from, newnode, alloc, hashclauses);
  906.     
  907.     newnode->hashjoinop =         from->hashjoinop;
  908.     
  909.     Node_Copy(from, newnode, alloc, hashjoinstate);
  910.     
  911.     newnode->hashjointable =         from->hashjointable;
  912.     newnode->hashjointablekey =     from->hashjointablekey;
  913.     newnode->hashjointablesize =     from->hashjointablesize;
  914.     newnode->hashdone =         from->hashdone;
  915.     
  916.     (*to) = newnode;
  917.     return true;
  918. }
  919.     
  920.  
  921. /* ----------------
  922.  *    CopyTempFields
  923.  *
  924.  *    This function copies the fields of the Temp node.  It is used by
  925.  *    all the copy functions for classes which inherit from Temp.
  926.  * ----------------
  927.  */
  928. bool CopyTempFields(from, newnode, alloc)
  929.     Temp     from;
  930.     Temp     newnode;
  931.     char *    (*alloc)();
  932. {
  933.     newnode->tempid =     from->tempid;
  934.     newnode->keycount = from->keycount;
  935.     return true;
  936. }
  937.     
  938.  
  939. /* ----------------
  940.  *    _copyTemp
  941.  * ----------------
  942.  */
  943. bool
  944. _copyTemp(from, to, alloc)
  945.     Temp    from;
  946.     Temp    *to;
  947.     char *    (*alloc)();
  948. {
  949.     Temp    newnode;
  950.  
  951.     COPY_CHECKARGS();
  952.     COPY_CHECKNULL();
  953.     COPY_NEW(Temp);
  954.     
  955.     /* ----------------
  956.      *    copy node superclass fields
  957.      * ----------------
  958.      */
  959.     CopyNodeFields(from, newnode, alloc);
  960.     CopyPlanFields(from, newnode, alloc);
  961.     CopyTempFields(from, newnode, alloc);
  962.  
  963.     (*to) = newnode;
  964.     return true;
  965. }
  966.  
  967. /* ----------------
  968.  *    _copyMaterial
  969.  * ----------------
  970.  */
  971. bool
  972. _copyMaterial(from, to, alloc)
  973.     Material    from;
  974.     Material    *to;
  975.     char *    (*alloc)();
  976. {
  977.     Material    newnode;
  978.  
  979.     COPY_CHECKARGS();
  980.     COPY_CHECKNULL();
  981.     COPY_NEW(Material);
  982.     
  983.     /* ----------------
  984.      *    copy node superclass fields
  985.      * ----------------
  986.      */
  987.     CopyNodeFields(from, newnode, alloc);
  988.     CopyPlanFields(from, newnode, alloc);
  989.     CopyTempFields(from, newnode, alloc);
  990.  
  991.     /* ----------------
  992.      *    copy remainder of node
  993.      * ----------------
  994.      */
  995.     Node_Copy(from, newnode, alloc, matstate);
  996.     
  997.     (*to) = newnode;
  998.     return true;
  999. }
  1000.     
  1001.  
  1002. /* ----------------
  1003.  *    _copySort
  1004.  * ----------------
  1005.  */
  1006. bool
  1007. _copySort(from, to, alloc)
  1008.     Sort    from;
  1009.     Sort    *to;
  1010.     char *    (*alloc)();
  1011. {
  1012.     Sort    newnode;
  1013.  
  1014.     COPY_CHECKARGS();
  1015.     COPY_CHECKNULL();
  1016.     COPY_NEW(Sort);
  1017.     
  1018.     /* ----------------
  1019.      *    copy node superclass fields
  1020.      * ----------------
  1021.      */
  1022.     CopyNodeFields(from, newnode, alloc);
  1023.     CopyPlanFields(from, newnode, alloc);
  1024.     CopyTempFields(from, newnode, alloc);
  1025.  
  1026.     /* ----------------
  1027.      *    copy remainder of node
  1028.      * ----------------
  1029.      */
  1030.     Node_Copy(from, newnode, alloc, sortstate);
  1031.     
  1032.     (*to) = newnode;
  1033.     return true;
  1034. }
  1035. /* ---------------
  1036.  *  _copyAgg
  1037.  * --------------
  1038.  */
  1039. bool
  1040. _copyAgg(from, to, alloc)
  1041.     Agg      from;
  1042.     Agg   *to;
  1043.     char * (*alloc)();
  1044. {
  1045.     Agg newnode;
  1046.     COPY_CHECKARGS();
  1047.     COPY_CHECKNULL();
  1048.     COPY_NEW(Agg);
  1049.  
  1050.     CopyNodeFields(from, newnode, alloc);
  1051.     CopyPlanFields(from, newnode, alloc);
  1052.     CopyTempFields(from, newnode, alloc);
  1053.  
  1054.     Node_Copy(from, newnode, alloc, aggstate);
  1055.  
  1056.     (*to) = newnode;
  1057.     return true;
  1058. }
  1059.  
  1060.     
  1061. /* ----------------
  1062.  *    _copyUnique
  1063.  * ----------------
  1064.  */
  1065. bool
  1066. _copyUnique(from, to, alloc)
  1067.     Unique    from;
  1068.     Unique    *to;
  1069.     char *    (*alloc)();
  1070. {
  1071.     Unique    newnode;
  1072.  
  1073.     COPY_CHECKARGS();
  1074.     COPY_CHECKNULL();
  1075.     COPY_NEW(Unique);
  1076.     
  1077.     /* ----------------
  1078.      *    copy node superclass fields
  1079.      * ----------------
  1080.      */
  1081.     CopyNodeFields(from, newnode, alloc);
  1082.     CopyPlanFields(from, newnode, alloc);
  1083.     CopyTempFields(from, newnode, alloc);
  1084.  
  1085.     /* ----------------
  1086.      *    copy remainder of node
  1087.      * ----------------
  1088.      */
  1089.     Node_Copy(from, newnode, alloc, uniquestate);
  1090.     
  1091.     (*to) = newnode;
  1092.     return true;
  1093. }
  1094.     
  1095.  
  1096. /* ----------------
  1097.  *    _copyHash
  1098.  * ----------------
  1099.  */
  1100. bool
  1101. _copyHash(from, to, alloc)
  1102.     Hash    from;
  1103.     Hash    *to;
  1104.     char *    (*alloc)();
  1105. {
  1106.     Hash    newnode;
  1107.  
  1108.     COPY_CHECKARGS();
  1109.     COPY_CHECKNULL();
  1110.     COPY_NEW(Hash);
  1111.     
  1112.     /* ----------------
  1113.      *    copy node superclass fields
  1114.      * ----------------
  1115.      */
  1116.     CopyNodeFields(from, newnode, alloc);
  1117.     CopyPlanFields(from, newnode, alloc);
  1118.  
  1119.     /* ----------------
  1120.      *    copy remainder of node
  1121.      * ----------------
  1122.      */
  1123.     Node_Copy(from, newnode, alloc, hashkey);
  1124.     Node_Copy(from, newnode, alloc, hashstate);
  1125.     
  1126.     newnode->hashtable =     from->hashtable;
  1127.     newnode->hashtablekey =     from->hashtablekey;
  1128.     newnode->hashtablesize =     from->hashtablesize;
  1129.     
  1130.     (*to) = newnode;
  1131.     return true;
  1132. }
  1133.  
  1134. /* ****************************************************************
  1135.  *               primnodes.h copy functions
  1136.  * ****************************************************************
  1137.  */
  1138.  
  1139. /* ----------------
  1140.  *    _copyResdom
  1141.  * ----------------
  1142.  */
  1143. bool
  1144. _copyResdom(from, to, alloc)
  1145.     Resdom    from;
  1146.     Resdom    *to;
  1147.     char *    (*alloc)();
  1148. {
  1149.     Resdom    newnode;
  1150.  
  1151.     COPY_CHECKARGS();
  1152.     COPY_CHECKNULL();
  1153.     COPY_NEW(Resdom);
  1154.     
  1155.     /* ----------------
  1156.      *    copy node superclass fields
  1157.      * ----------------
  1158.      */
  1159.     CopyNodeFields(from, newnode, alloc);
  1160.  
  1161.     /* ----------------
  1162.      *    copy remainder of node
  1163.      *
  1164.      * XXX reskeyop is USED as an int within the print functions
  1165.      *        so that's what the copy function uses, but its
  1166.      *        declared as an OperatorTupleForm in primnodes.h
  1167.      *      One or the other is wrong, and I'm assuming
  1168.      *        it should be an int.  -cim 5/1/90
  1169.      * ----------------
  1170.      */
  1171.     newnode->resno   =     from->resno;
  1172.     newnode->restype =     from->restype;
  1173.     newnode->rescomplex = from->rescomplex;
  1174.     newnode->reslen  =     from->reslen;
  1175.  
  1176.     if (from->resname != NULL)
  1177.     newnode->resname = (Name)
  1178.         strcpy((char *) COPYALLOC(strlen(from->resname)+1), from->resname);
  1179.     else
  1180.     newnode->resname = (Name) NULL;
  1181.     
  1182.     newnode->reskey  =     from->reskey;
  1183.     newnode->reskeyop = from->reskeyop; /* USED AS AN INT (see above) */
  1184.     newnode->resjunk =     from->resjunk;
  1185.     
  1186.     (*to) = newnode;
  1187.     return true;
  1188. }
  1189.     
  1190. bool
  1191. _copyFjoin(from, to, alloc)
  1192.     Fjoin    from;
  1193.     Fjoin    *to;
  1194.     char *    (*alloc)();
  1195. {
  1196.     Fjoin    newnode;
  1197.  
  1198.     COPY_CHECKARGS();
  1199.     COPY_CHECKNULL();
  1200.     COPY_NEW(Fjoin);
  1201.     
  1202.     /* ----------------
  1203.      *    copy node superclass fields
  1204.      * ----------------
  1205.      */
  1206.     CopyNodeFields(from, newnode, alloc);
  1207.  
  1208.     newnode->fj_initialized = from->fj_initialized;
  1209.     newnode->fj_nNodes      = from->fj_nNodes;
  1210.  
  1211.     Node_Copy(from, newnode, alloc, fj_innerNode);
  1212.  
  1213.     newnode->fj_results     = (DatumPtr)
  1214.     COPYALLOC((from->fj_nNodes)*sizeof(Datum));
  1215.  
  1216.     newnode->fj_alwaysDone  = (BoolPtr)
  1217.     COPYALLOC((from->fj_nNodes)*sizeof(bool));
  1218.  
  1219.     bcopy(newnode->fj_results,
  1220.       from->fj_results,
  1221.       (from->fj_nNodes)*sizeof(Datum));
  1222.  
  1223.     bcopy(newnode->fj_alwaysDone,
  1224.       from->fj_alwaysDone,
  1225.       (from->fj_nNodes)*sizeof(bool));
  1226.     
  1227.     (*to) = newnode;
  1228.     return true;
  1229. }
  1230. /* ----------------
  1231.  *    CopyExprFields
  1232.  *
  1233.  *    This function copies the fields of the Expr node.  It is used by
  1234.  *    all the copy functions for classes which inherit from Expr.
  1235.  * ----------------
  1236.  */
  1237. bool
  1238. CopyExprFields(from, newnode, alloc)
  1239.     Expr     from;
  1240.     Expr     newnode;
  1241.     char *    (*alloc)();
  1242. {
  1243.     return true;
  1244. }
  1245.  
  1246. /* ----------------
  1247.  *    _copyExpr
  1248.  * ----------------
  1249.  */
  1250. bool
  1251. _copyExpr(from, to, alloc)
  1252.     Expr    from;
  1253.     Expr    *to;
  1254.     char *    (*alloc)();
  1255. {
  1256.     Expr    newnode;
  1257.  
  1258.     COPY_CHECKARGS();
  1259.     COPY_CHECKNULL();
  1260.     COPY_NEW(Expr);
  1261.     
  1262.     /* ----------------
  1263.      *    copy node superclass fields
  1264.      * ----------------
  1265.      */
  1266.     CopyNodeFields(from, newnode, alloc);
  1267.     CopyExprFields(from, newnode, alloc);
  1268.  
  1269.     (*to) = newnode;
  1270.     return true;
  1271. }
  1272.  
  1273. bool
  1274. _copyIter(from, to, alloc)
  1275.     Iter    from;
  1276.     Iter    *to;
  1277.     char *    (*alloc)();
  1278. {
  1279.     Iter    newnode;
  1280.  
  1281.     COPY_CHECKARGS();
  1282.     COPY_CHECKNULL();
  1283.     COPY_NEW(Iter);
  1284.     
  1285.     CopyNodeFields(from, newnode, alloc);
  1286.  
  1287.     Node_Copy(from, newnode, alloc, iterexpr);
  1288.  
  1289.     (*to) = newnode;
  1290.     return true;
  1291. }
  1292. /* ----------------
  1293.  *    _copyVar
  1294.  * ----------------
  1295.  */
  1296. bool
  1297. _copyVar(from, to, alloc)
  1298.     Var    from;
  1299.     Var    *to;
  1300.     char *    (*alloc)();
  1301. {
  1302.     Var    newnode;
  1303.  
  1304.     COPY_CHECKARGS();
  1305.     COPY_CHECKNULL();
  1306.     COPY_NEW(Var);
  1307.     
  1308.     /* ----------------
  1309.      *    copy node superclass fields
  1310.      * ----------------
  1311.      */
  1312.     CopyNodeFields(from, newnode, alloc);
  1313.     CopyExprFields(from, newnode, alloc);
  1314.  
  1315.     /* ----------------
  1316.      *    copy remainder of node
  1317.      * ----------------
  1318.      */
  1319.     newnode->varno =      from->varno;
  1320.     newnode->varattno =  from->varattno;
  1321.     newnode->vartype =      from->vartype;
  1322.     
  1323.     Node_Copy(from, newnode, alloc, varid);    
  1324.  
  1325.     /* ----------------
  1326.      *    don't copy var's cached slot pointer!
  1327.      * ----------------
  1328.      */
  1329.     newnode->varslot =    NULL;
  1330.     
  1331.     (*to) = newnode;
  1332.     return true;
  1333. }
  1334.  
  1335. bool
  1336. _copyArray(from, to, alloc)
  1337.     Array    from;
  1338.     Array    *to;
  1339.     char *    (*alloc)();
  1340.  
  1341. {
  1342.     Array    newnode;
  1343.  
  1344.     COPY_CHECKARGS();
  1345.     COPY_CHECKNULL();
  1346.     COPY_NEW(Array);
  1347.  
  1348.     /* ----------------
  1349.      *    copy node superclass fields
  1350.      * ----------------
  1351.      */
  1352.     CopyNodeFields(from, newnode, alloc);
  1353.     CopyExprFields(from, newnode, alloc);
  1354.  
  1355.     /* ----------------
  1356.      *    copy remainder of node
  1357.      * ----------------
  1358.      */
  1359.     newnode->arrayelemtype =     from->arrayelemtype;
  1360.     newnode->arrayelemlength =     from->arrayelemlength;
  1361.     newnode->arrayelembyval =     from->arrayelembyval;
  1362.     newnode->arraylow =     from->arraylow;
  1363.     newnode->arrayhigh =     from->arrayhigh;
  1364.     newnode->arraylen =     from->arraylen;
  1365.  
  1366.     (*to) = newnode;
  1367.     return true;
  1368. }
  1369.  
  1370. bool
  1371. _copyArrayRef(from, to, alloc)
  1372.     ArrayRef    from;
  1373.     ArrayRef    *to;
  1374.     char *    (*alloc)();
  1375.  
  1376. {
  1377.     ArrayRef    newnode;
  1378.  
  1379.     COPY_CHECKARGS();
  1380.     COPY_CHECKNULL();
  1381.     COPY_NEW(ArrayRef);
  1382.  
  1383.     /* ----------------
  1384.      *    copy node superclass fields
  1385.      * ----------------
  1386.      */
  1387.     CopyNodeFields(from, newnode, alloc);
  1388.     CopyExprFields(from, newnode, alloc);
  1389.  
  1390.     /* ----------------
  1391.      *    copy remainder of node
  1392.      * ----------------
  1393.      */
  1394.     newnode->refelemtype =     from->refelemtype;
  1395.     newnode->refattrlength =     from->refattrlength;
  1396.     newnode->refelemlength =     from->refelemlength;
  1397.     newnode->refelembyval =     from->refelembyval;
  1398.  
  1399.     (void) NodeCopy(from->refindexpr, &(newnode->refindexpr), alloc);
  1400.     (void) NodeCopy(from->refexpr, &(newnode->refexpr), alloc);
  1401.  
  1402.     (*to) = newnode;
  1403.     return true;
  1404. }
  1405.  
  1406. /* ----------------
  1407.  *    _copyOper
  1408.  * ----------------
  1409.  */
  1410. bool
  1411. _copyOper(from, to, alloc)
  1412.     Oper    from;
  1413.     Oper    *to;
  1414.     char *    (*alloc)();
  1415. {
  1416.     Oper    newnode;
  1417.  
  1418.     COPY_CHECKARGS();
  1419.     COPY_CHECKNULL();
  1420.     COPY_NEW(Oper);
  1421.     
  1422.     /* ----------------
  1423.      *    copy node superclass fields
  1424.      * ----------------
  1425.      */
  1426.     CopyNodeFields(from, newnode, alloc);
  1427.     CopyExprFields(from, newnode, alloc);
  1428.  
  1429.     /* ----------------
  1430.      *    copy remainder of node
  1431.      * ----------------
  1432.      */
  1433.     newnode->opno =            from->opno;
  1434.     newnode->opid =            from->opid;
  1435.     newnode->oprelationlevel =     from->oprelationlevel;
  1436.     newnode->opresulttype =        from->opresulttype;
  1437.     newnode->opsize =            from->opsize;
  1438.  
  1439.     /*
  1440.      * NOTE: shall we copy the cache structure or just the pointer ?
  1441.      * Alternatively we can set 'op_fcache' to NULL, in which
  1442.      * case the executor will initialize it when it needs it...
  1443.      */
  1444.     newnode->op_fcache =       from->op_fcache;
  1445.     
  1446.     (*to) = newnode;
  1447.     return true;
  1448. }
  1449.  
  1450. /* ----------------
  1451.  *    _copyConst
  1452.  * ----------------
  1453.  */
  1454. bool
  1455. _copyConst(from, to, alloc)
  1456.     Const    from;
  1457.     Const    *to;
  1458.     char *    (*alloc)();
  1459. {
  1460.     static ObjectId     cached_type;
  1461.     static bool        cached_typbyval;
  1462.  
  1463.     Const    newnode;
  1464.  
  1465.     COPY_CHECKARGS();
  1466.     COPY_CHECKNULL();
  1467.     COPY_NEW(Const);
  1468.     
  1469.     /* ----------------
  1470.      *    copy node superclass fields
  1471.      * ----------------
  1472.      */
  1473.     CopyNodeFields(from, newnode, alloc);
  1474.     CopyExprFields(from, newnode, alloc);
  1475.  
  1476.     /* ----------------
  1477.      *    copy remainder of node
  1478.      * ----------------
  1479.      */
  1480.     newnode->consttype =     from->consttype;
  1481.     newnode->constlen =     from->constlen;
  1482.  
  1483.     /* ----------------
  1484.      *    XXX super cheesy hack until parser/planner
  1485.      *  puts in the right values here.
  1486.      * ----------------
  1487.      */
  1488.     if (cached_type != from->consttype) {
  1489.     HeapTuple    typeTuple;
  1490.     TypeTupleForm    typeStruct;
  1491.     
  1492.     /* ----------------
  1493.      *   get the type tuple corresponding to the paramList->type,
  1494.      *   If this fails, returnValue has been pre-initialized
  1495.      *   to "null" so we just return it.
  1496.      * ----------------
  1497.      */
  1498.     typeTuple = SearchSysCacheTuple(TYPOID,
  1499.                     from->consttype,
  1500.                     NULL,
  1501.                     NULL,
  1502.                     NULL);
  1503.  
  1504.     /* ----------------
  1505.      *   get the type length and by-value from the type tuple and
  1506.      *   save the information in our one element cache.
  1507.      * ----------------
  1508.      */
  1509.     Assert(PointerIsValid(typeTuple));
  1510.     
  1511.     typeStruct = (TypeTupleForm) GETSTRUCT(typeTuple);
  1512.     cached_typbyval = (typeStruct)->typbyval ? true : false ;
  1513.     cached_type = from->consttype;
  1514.     }
  1515.     
  1516.     from->constbyval = cached_typbyval;
  1517.     
  1518.     if (!from->constisnull) {
  1519.     /* ----------------
  1520.      *    copying the Datum in a const node is a bit trickier
  1521.      *  because it might be a pointer and it might also be of
  1522.      *  variable length...
  1523.      * ----------------
  1524.      */
  1525.     if (from->constbyval == true) {
  1526.         /* ----------------
  1527.          *  passed by value so just copy the datum.
  1528.          * ----------------
  1529.          */
  1530.         newnode->constvalue =     from->constvalue;
  1531.     } else {
  1532.         /* ----------------
  1533.          *  not passed by value. datum contains a pointer.
  1534.          * ----------------
  1535.          */
  1536.         if (from->constlen != -1) {
  1537.         /* ----------------
  1538.          *    fixed length structure
  1539.          * ----------------
  1540.          */
  1541.         newnode->constvalue = PointerGetDatum(COPYALLOC(from->constlen));
  1542.         bcopy(from->constvalue, newnode->constvalue, from->constlen);
  1543.         } else {
  1544.         /* ----------------
  1545.          *    variable length structure.  here the length is stored
  1546.          *  in the first int pointed to by the constval.
  1547.          * ----------------
  1548.          */
  1549.         int length;
  1550.         length = *((int *) from->constvalue);
  1551.         newnode->constvalue = PointerGetDatum(COPYALLOC(length));
  1552.         bcopy(from->constvalue, newnode->constvalue, length);
  1553.         }
  1554.     }
  1555.     }
  1556.     else {
  1557.     newnode->constvalue = from->constvalue;
  1558.     }
  1559.     newnode->constisnull =     from->constisnull;
  1560.     newnode->constbyval =     from->constbyval;
  1561.     
  1562.     (*to) = newnode;
  1563.     return true;
  1564. }
  1565.  
  1566. /* ----------------
  1567.  *    _copyParam
  1568.  * ----------------
  1569.  */
  1570. bool
  1571. _copyParam(from, to, alloc)
  1572.     Param    from;
  1573.     Param    *to;
  1574.     char *    (*alloc)();
  1575. {
  1576.     Param    newnode;
  1577.  
  1578.     COPY_CHECKARGS();
  1579.     COPY_CHECKNULL();
  1580.     COPY_NEW(Param);
  1581.     
  1582.     /* ----------------
  1583.      *    copy node superclass fields
  1584.      * ----------------
  1585.      */
  1586.     CopyNodeFields(from, newnode, alloc);
  1587.     CopyExprFields(from, newnode, alloc);
  1588.  
  1589.     /* ----------------
  1590.      *    copy remainder of node
  1591.      * ----------------
  1592.      */
  1593.     newnode->paramkind = from->paramkind;
  1594.     newnode->paramid = from->paramid;
  1595.  
  1596.     if (from->paramname != NULL)
  1597.     newnode->paramname = (Name)
  1598.         strcpy((char *) COPYALLOC(strlen(from->paramname)+1),
  1599.            from->paramname);
  1600.     else
  1601.     newnode->paramname = (Name) NULL;
  1602.     
  1603.     newnode->paramtype = from->paramtype;
  1604.     Node_Copy(from, newnode, alloc, param_tlist);
  1605.     
  1606.     (*to) = newnode;
  1607.     return true;
  1608. }
  1609.  
  1610. /* ----------------
  1611.  *    _copyFunc
  1612.  * ----------------
  1613.  */
  1614. bool
  1615. _copyFunc(from, to, alloc)
  1616.     Func    from;
  1617.     Func    *to;
  1618.     char *    (*alloc)();
  1619. {
  1620.     Func    newnode;
  1621.  
  1622.     COPY_CHECKARGS();
  1623.     COPY_CHECKNULL();
  1624.     COPY_NEW(Func);
  1625.     
  1626.     /* ----------------
  1627.      *    copy node superclass fields
  1628.      * ----------------
  1629.      */
  1630.     CopyNodeFields(from, newnode, alloc);
  1631.     CopyExprFields(from, newnode, alloc);
  1632.  
  1633.     /* ----------------
  1634.      *    copy remainder of node
  1635.      * ----------------
  1636.      */
  1637.     newnode->funcid =         from->funcid;
  1638.     newnode->functype =     from->functype;
  1639.     newnode->funcisindex =     from->funcisindex;
  1640.     newnode->funcsize =     from->funcsize;
  1641.     newnode->func_fcache =     from->func_fcache;
  1642.     Node_Copy(from, newnode, alloc, func_tlist);
  1643.     Node_Copy(from, newnode, alloc, func_planlist);
  1644.     
  1645.     (*to) = newnode;
  1646.     return true;
  1647. }
  1648.  
  1649. /* ****************************************************************
  1650.  *            relation.h copy functions
  1651.  * ****************************************************************
  1652.  */
  1653.  
  1654. /* ----------------
  1655.  *    _copyRel
  1656.  * ----------------
  1657.  */
  1658. bool
  1659. _copyRel(from, to, alloc)
  1660.     Rel    from;
  1661.     Rel    *to;
  1662.     char *    (*alloc)();
  1663. {
  1664.     Rel    newnode;
  1665.  
  1666.     COPY_CHECKARGS();
  1667.     COPY_CHECKNULL();
  1668.     COPY_NEW(Rel);
  1669.     
  1670.     /* ----------------
  1671.      *    copy node superclass fields
  1672.      * ----------------
  1673.      */
  1674.     CopyNodeFields(from, newnode, alloc);
  1675.  
  1676.     /* ----------------
  1677.      *    copy remainder of node
  1678.      * ----------------
  1679.      */
  1680.     Node_Copy(from, newnode, alloc, relids);
  1681.     
  1682.     newnode->indexed = from->indexed;
  1683.     newnode->pages =   from->pages;
  1684.     newnode->tuples =  from->tuples;
  1685.     newnode->size =    from->size;
  1686.     newnode->width =   from->width;
  1687.     newnode->indproc = from->indproc;
  1688.  
  1689.     Node_Copy(from, newnode, alloc, targetlist);
  1690.     Node_Copy(from, newnode, alloc, pathlist);
  1691.     Node_Copy(from, newnode, alloc, unorderedpath);
  1692.     Node_Copy(from, newnode, alloc, cheapestpath);
  1693.     Node_Copy(from, newnode, alloc, classlist);
  1694.     Node_Copy(from, newnode, alloc, indexkeys);
  1695.     Node_Copy(from, newnode, alloc, ordering);
  1696.     Node_Copy(from, newnode, alloc, clauseinfo);
  1697.     Node_Copy(from, newnode, alloc, joininfo);
  1698.     Node_Copy(from, newnode, alloc, innerjoin);
  1699.     Node_Copy(from, newnode, alloc, superrels);
  1700.     
  1701.     (*to) = newnode;
  1702.     return true;
  1703. }
  1704.  
  1705. /* ----------------
  1706.  *    _copySortKey
  1707.  * ----------------
  1708.  */
  1709. bool
  1710. _copySortKey(from, to, alloc)
  1711.     SortKey    from;
  1712.     SortKey    *to;
  1713.     char *    (*alloc)();
  1714. {
  1715.     SortKey    newnode;
  1716.  
  1717.     COPY_CHECKARGS();
  1718.     COPY_CHECKNULL();
  1719.     COPY_NEW(SortKey);
  1720.     
  1721.     /* ----------------
  1722.      *    copy node superclass fields
  1723.      * ----------------
  1724.      */
  1725.     CopyNodeFields(from, newnode, alloc);
  1726.  
  1727.     /* ----------------
  1728.      *    copy remainder of node
  1729.      * ----------------
  1730.      */
  1731.     Node_Copy(from, newnode, alloc, varkeys);
  1732.     Node_Copy(from, newnode, alloc, sortkeys);
  1733.     Node_Copy(from, newnode, alloc, relid);
  1734.     Node_Copy(from, newnode, alloc, sortorder);
  1735.  
  1736.     (*to) = newnode;
  1737.     return true;
  1738. }
  1739.  
  1740. /* ----------------
  1741.  *    CopyPathFields
  1742.  *
  1743.  *    This function copies the fields of the Path node.  It is used by
  1744.  *    all the copy functions for classes which inherit from Path.
  1745.  * ----------------
  1746.  */
  1747. bool CopyPathFields(from, newnode, alloc)
  1748.     Path     from;
  1749.     Path     newnode;
  1750.     char *    (*alloc)();
  1751. {
  1752.     newnode->pathtype =      from->pathtype;
  1753.     /* Modify the next line, since it causes the copying to cycle
  1754.        (i.e. the parent points right back here! 
  1755.        -- JMH, 7/7/92.
  1756.        Old version:
  1757.        Node_Copy(from, newnode, alloc, parent);
  1758.        */
  1759.     newnode->parent =           from->parent;
  1760.     
  1761.     newnode->path_cost =     from->path_cost;
  1762.     
  1763.     Node_Copy(from, newnode, alloc, p_ordering);
  1764.     Node_Copy(from, newnode, alloc, keys);
  1765.     Node_Copy(from, newnode, alloc, pathsortkey);
  1766.     
  1767.     newnode->outerjoincost =     from->outerjoincost;
  1768.     
  1769.     Node_Copy(from, newnode, alloc, joinid);
  1770.     Node_Copy(from, newnode, alloc, locclauseinfo);
  1771.     return true;
  1772. }
  1773.  
  1774. /* ----------------
  1775.  *    _copyPath
  1776.  * ----------------
  1777.  */
  1778. bool
  1779. _copyPath(from, to, alloc)
  1780.     Path    from;
  1781.     Path    *to;
  1782.     char *    (*alloc)();
  1783. {
  1784.     Path    newnode;
  1785.  
  1786.     COPY_CHECKARGS();
  1787.     COPY_CHECKNULL();
  1788.     COPY_NEW(Path);
  1789.     
  1790.     /* ----------------
  1791.      *    copy the node superclass fields
  1792.      * ----------------
  1793.      */
  1794.     CopyNodeFields(from, newnode, alloc);
  1795.     CopyPathFields(from, newnode, alloc);
  1796.     
  1797.     (*to) = newnode;
  1798.     return true;
  1799. }
  1800.  
  1801. /* ----------------
  1802.  *    _copyIndexPath
  1803.  * ----------------
  1804.  */
  1805. bool
  1806. _copyIndexPath(from, to, alloc)
  1807.     IndexPath    from;
  1808.     IndexPath    *to;
  1809.     char *    (*alloc)();
  1810. {
  1811.     IndexPath    newnode;
  1812.  
  1813.     COPY_CHECKARGS();
  1814.     COPY_CHECKNULL();
  1815.     COPY_NEW(IndexPath);
  1816.     
  1817.     /* ----------------
  1818.      *    copy the node superclass fields
  1819.      * ----------------
  1820.      */
  1821.     CopyNodeFields(from, newnode, alloc);
  1822.     CopyPathFields(from, newnode, alloc);
  1823.  
  1824.     /* ----------------
  1825.      *    copy remainder of node
  1826.      * ----------------
  1827.      */
  1828.     Node_Copy(from, newnode, alloc, indexid);
  1829.     Node_Copy(from, newnode, alloc, indexqual);
  1830.  
  1831.     (*to) = newnode;
  1832.     return true;
  1833. }
  1834.  
  1835. /* ----------------
  1836.  *    CopyJoinPathFields
  1837.  *
  1838.  *    This function copies the fields of the JoinPath node.  It is used by
  1839.  *    all the copy functions for classes which inherit from JoinPath.
  1840.  * ----------------
  1841.  */
  1842. bool CopyJoinPathFields(from, newnode, alloc)
  1843.     JoinPath     from;
  1844.     JoinPath     newnode;
  1845.     char *    (*alloc)();
  1846. {
  1847.     Node_Copy(from, newnode, alloc, pathclauseinfo);
  1848.     Node_Copy(from, newnode, alloc, outerjoinpath);
  1849.     Node_Copy(from, newnode, alloc, innerjoinpath);
  1850.     
  1851.     return true;
  1852. }
  1853.  
  1854. /* ----------------
  1855.  *    _copyJoinPath
  1856.  * ----------------
  1857.  */
  1858. bool
  1859. _copyJoinPath(from, to, alloc)
  1860.     JoinPath    from;
  1861.     JoinPath    *to;
  1862.     char *    (*alloc)();
  1863. {
  1864.     JoinPath    newnode;
  1865.  
  1866.     COPY_CHECKARGS();
  1867.     COPY_CHECKNULL();
  1868.     COPY_NEW(JoinPath);
  1869.     
  1870.     /* ----------------
  1871.      *    copy the node superclass fields
  1872.      * ----------------
  1873.      */
  1874.     CopyNodeFields(from, newnode, alloc);
  1875.     CopyPathFields(from, newnode, alloc);
  1876.     CopyJoinPathFields(from, newnode, alloc);
  1877.     
  1878.     (*to) = newnode;
  1879.     return true;
  1880. }
  1881.  
  1882. /* ----------------
  1883.  *    _copyMergePath
  1884.  * ----------------
  1885.  */
  1886. bool
  1887. _copyMergePath(from, to, alloc)
  1888.     MergePath    from;
  1889.     MergePath    *to;
  1890.     char *    (*alloc)();
  1891. {
  1892.     MergePath    newnode;
  1893.  
  1894.     COPY_CHECKARGS();
  1895.     COPY_CHECKNULL();
  1896.     COPY_NEW(MergePath);
  1897.     
  1898.     /* ----------------
  1899.      *    copy the node superclass fields
  1900.      * ----------------
  1901.      */
  1902.     CopyNodeFields(from, newnode, alloc);
  1903.     CopyPathFields(from, newnode, alloc);
  1904.     CopyJoinPathFields(from, newnode, alloc);
  1905.  
  1906.     /* ----------------
  1907.      *    copy the remainder of the node
  1908.      * ----------------
  1909.      */
  1910.     Node_Copy(from, newnode, alloc, path_mergeclauses);
  1911.     Node_Copy(from, newnode, alloc, outersortkeys);
  1912.     Node_Copy(from, newnode, alloc, innersortkeys);
  1913.     
  1914.     (*to) = newnode;
  1915.     return true;
  1916. }
  1917.  
  1918. /* ----------------
  1919.  *    _copyHashPath
  1920.  * ----------------
  1921.  */
  1922. bool
  1923. _copyHashPath(from, to, alloc)
  1924.     HashPath    from;
  1925.     HashPath    *to;
  1926.     char *    (*alloc)();
  1927. {
  1928.     HashPath    newnode;
  1929.  
  1930.     COPY_CHECKARGS();
  1931.     COPY_CHECKNULL();
  1932.     COPY_NEW(HashPath);
  1933.     
  1934.     /* ----------------
  1935.      *    copy the node superclass fields
  1936.      * ----------------
  1937.      */
  1938.     CopyNodeFields(from, newnode, alloc);
  1939.     CopyPathFields(from, newnode, alloc);
  1940.     CopyJoinPathFields(from, newnode, alloc);
  1941.  
  1942.     /* ----------------
  1943.      *    copy remainder of node
  1944.      * ----------------
  1945.      */
  1946.     Node_Copy(from, newnode, alloc, path_hashclauses);
  1947.     Node_Copy(from, newnode, alloc, outerhashkeys);
  1948.     Node_Copy(from, newnode, alloc, innerhashkeys);
  1949.     
  1950.     (*to) = newnode;
  1951.     return true;
  1952. }
  1953.  
  1954. /* ----------------
  1955.  *    _copyOrderKey
  1956.  * ----------------
  1957.  */
  1958. bool
  1959. _copyOrderKey(from, to, alloc)
  1960.     OrderKey    from;
  1961.     OrderKey    *to;
  1962.     char *    (*alloc)();
  1963. {
  1964.     OrderKey    newnode;
  1965.  
  1966.     COPY_CHECKARGS();
  1967.     COPY_CHECKNULL();
  1968.     COPY_NEW(OrderKey);
  1969.     
  1970.     /* ----------------
  1971.      *    copy node superclass fields
  1972.      * ----------------
  1973.      */
  1974.     CopyNodeFields(from, newnode, alloc);
  1975.  
  1976.     /* ----------------
  1977.      *    copy remainder of node
  1978.      * ----------------
  1979.      */
  1980.     newnode->attribute_number =     from->attribute_number;
  1981.     newnode->array_index =         from->array_index;
  1982.     
  1983.     (*to) = newnode;
  1984.     return true;
  1985. }
  1986.     
  1987.  
  1988. /* ----------------
  1989.  *    _copyJoinKey
  1990.  * ----------------
  1991.  */
  1992. bool
  1993. _copyJoinKey(from, to, alloc)
  1994.     JoinKey    from;
  1995.     JoinKey    *to;
  1996.     char *    (*alloc)();
  1997. {
  1998.     JoinKey    newnode;
  1999.  
  2000.     COPY_CHECKARGS();
  2001.     COPY_CHECKNULL();
  2002.     COPY_NEW(JoinKey);
  2003.     
  2004.     /* ----------------
  2005.      *    copy node superclass fields
  2006.      * ----------------
  2007.      */
  2008.     CopyNodeFields(from, newnode, alloc);
  2009.  
  2010.     /* ----------------
  2011.      *    copy remainder of node
  2012.      * ----------------
  2013.      */
  2014.     Node_Copy(from, newnode, alloc, outer);
  2015.     Node_Copy(from, newnode, alloc, inner);
  2016.     
  2017.     (*to) = newnode;
  2018.     return true;
  2019. }
  2020.    
  2021. /* ----------------
  2022.  *    _copyMergeOrder
  2023.  * ----------------
  2024.  */
  2025. bool
  2026. _copyMergeOrder(from, to, alloc)
  2027.     MergeOrder    from;
  2028.     MergeOrder    *to;
  2029.     char *    (*alloc)();
  2030. {
  2031.     MergeOrder    newnode;
  2032.  
  2033.     COPY_CHECKARGS();
  2034.     COPY_CHECKNULL();
  2035.     COPY_NEW(MergeOrder);
  2036.     
  2037.     /* ----------------
  2038.      *    copy node superclass fields
  2039.      * ----------------
  2040.      */
  2041.     CopyNodeFields(from, newnode, alloc);
  2042.  
  2043.     /* ----------------
  2044.      *    copy remainder of node
  2045.      * ----------------
  2046.      */
  2047.     newnode->join_operator =     from->join_operator;
  2048.     newnode->left_operator =     from->left_operator;
  2049.     newnode->right_operator =     from->right_operator;
  2050.     newnode->left_type =     from->left_type;
  2051.     newnode->right_type =     from->right_type;
  2052.     
  2053.     (*to) = newnode;
  2054.     return true;
  2055. }
  2056.     
  2057. /* ----------------
  2058.  *    _copyCInfo
  2059.  * ----------------
  2060.  */
  2061. bool
  2062. _copyCInfo(from, to, alloc)
  2063.     CInfo    from;
  2064.     CInfo    *to;
  2065.     char *    (*alloc)();
  2066. {
  2067.     CInfo    newnode;
  2068.  
  2069.     COPY_CHECKARGS();
  2070.     COPY_CHECKNULL();
  2071.     COPY_NEW(CInfo);
  2072.     
  2073.     /* ----------------
  2074.      *    copy node superclass fields
  2075.      * ----------------
  2076.      */
  2077.     CopyNodeFields(from, newnode, alloc);
  2078.  
  2079.     /* ----------------
  2080.      *    copy remainder of node
  2081.      * ----------------
  2082.      */
  2083.     Node_Copy(from, newnode, alloc, clause);
  2084.     
  2085.     newnode->selectivity =     from->selectivity;
  2086.     newnode->notclause =     from->notclause;
  2087.     
  2088.     Node_Copy(from, newnode, alloc, indexids);
  2089.     Node_Copy(from, newnode, alloc, mergesortorder);
  2090.     newnode->hashjoinoperator = from->hashjoinoperator;
  2091.     Node_Copy(from, newnode, alloc, cinfojoinid);
  2092.     
  2093.     (*to) = newnode;
  2094.     return true;
  2095. }
  2096.  
  2097. /* ----------------
  2098.  *    CopyJoinMethodFields
  2099.  *
  2100.  *    This function copies the fields of the JoinMethod node.  It is used by
  2101.  *    all the copy functions for classes which inherit from JoinMethod.
  2102.  * ----------------
  2103.  */
  2104. bool CopyJoinMethodFields(from, newnode, alloc)
  2105.     JoinMethod     from;
  2106.     JoinMethod     newnode;
  2107.     char *    (*alloc)();
  2108. {
  2109.     Node_Copy(from, newnode, alloc, jmkeys);
  2110.     Node_Copy(from, newnode, alloc, clauses);
  2111.     return true;
  2112. }
  2113.     
  2114. /* ----------------
  2115.  *    _copyJoinMethod
  2116.  * ----------------
  2117.  */
  2118. bool
  2119. _copyJoinMethod(from, to, alloc)
  2120.     JoinMethod    from;
  2121.     JoinMethod    *to;
  2122.     char *    (*alloc)();
  2123. {
  2124.     JoinMethod    newnode;
  2125.  
  2126.     COPY_CHECKARGS();
  2127.     COPY_CHECKNULL();
  2128.     COPY_NEW(JoinMethod);
  2129.     
  2130.     /* ----------------
  2131.      *    copy node superclass fields
  2132.      * ----------------
  2133.      */
  2134.     CopyNodeFields(from, newnode, alloc);
  2135.     CopyJoinMethodFields(from, newnode, alloc);
  2136.  
  2137.     (*to) = newnode;
  2138.     return true;
  2139. }
  2140.     
  2141. /* ----------------
  2142.  *    _copyHInfo
  2143.  * ----------------
  2144.  */
  2145. bool
  2146. _copyHInfo(from, to, alloc)
  2147.     HInfo    from;
  2148.     HInfo    *to;
  2149.     char *    (*alloc)();
  2150. {
  2151.     HInfo    newnode;
  2152.  
  2153.     COPY_CHECKARGS();
  2154.     COPY_CHECKNULL();
  2155.     COPY_NEW(HInfo);
  2156.     
  2157.     /* ----------------
  2158.      *    copy node superclass fields
  2159.      * ----------------
  2160.      */
  2161.     CopyNodeFields(from, newnode, alloc);
  2162.     CopyJoinMethodFields(from, newnode, alloc);
  2163.  
  2164.     /* ----------------
  2165.      *    copy remainder of node
  2166.      * ----------------
  2167.      */
  2168.     newnode->hashop = from->hashop;
  2169.     
  2170.     (*to) = newnode;
  2171.     return true;
  2172. }
  2173.     
  2174. /* ----------------
  2175.  *    _copyMInfo
  2176.  * ----------------
  2177.  */
  2178. bool
  2179. _copyMInfo(from, to, alloc)
  2180.     MInfo    from;
  2181.     MInfo    *to;
  2182.     char *    (*alloc)();
  2183. {
  2184.     MInfo    newnode;
  2185.  
  2186.     COPY_CHECKARGS();
  2187.     COPY_CHECKNULL();
  2188.     COPY_NEW(MInfo);
  2189.     
  2190.     /* ----------------
  2191.      *    copy node superclass fields
  2192.      * ----------------
  2193.      */
  2194.     CopyNodeFields(from, newnode, alloc);
  2195.     CopyJoinMethodFields(from, newnode, alloc);
  2196.  
  2197.     /* ----------------
  2198.      *    copy remainder of node
  2199.      * ----------------
  2200.      */
  2201.     Node_Copy(from, newnode, alloc, m_ordering);
  2202.     
  2203.     (*to) = newnode;
  2204.     return true;
  2205. }
  2206.     
  2207. /* ----------------
  2208.  *    _copyJInfo
  2209.  * ----------------
  2210.  */
  2211. bool
  2212. _copyJInfo(from, to, alloc)
  2213.     JInfo    from;
  2214.     JInfo    *to;
  2215.     char *    (*alloc)();
  2216. {
  2217.     JInfo    newnode;
  2218.  
  2219.     COPY_CHECKARGS();
  2220.     COPY_CHECKNULL();
  2221.     COPY_NEW(JInfo);
  2222.     
  2223.     /* ----------------
  2224.      *    copy node superclass fields
  2225.      * ----------------
  2226.      */
  2227.     CopyNodeFields(from, newnode, alloc);
  2228.  
  2229.     /* ----------------
  2230.      *    copy remainder of node
  2231.      * ----------------
  2232.      */
  2233.     Node_Copy(from, newnode, alloc, otherrels);
  2234.     Node_Copy(from, newnode, alloc, jinfoclauseinfo);
  2235.     
  2236.     newnode->mergesortable = from->mergesortable;
  2237.     newnode->hashjoinable =  from->hashjoinable;
  2238.     newnode->inactive =      from->inactive;
  2239.     
  2240.     (*to) = newnode;
  2241.     return true;
  2242. }
  2243.  
  2244. /* ****************
  2245.  *          mnodes.h routines have no copy functions
  2246.  * ****************
  2247.  */
  2248.  
  2249. /* ****************************************************************
  2250.  *            pg_lisp.h copy functions
  2251.  * ****************************************************************
  2252.  */
  2253.  
  2254. /* ----------------
  2255.  *    _copyLispValue
  2256.  * ----------------
  2257.  */
  2258. bool
  2259. _copyLispValue(from, to, alloc)
  2260.     LispValue    from;
  2261.     LispValue    *to;
  2262.     char *    (*alloc)();
  2263. {
  2264.     LispValue    newnode;
  2265.  
  2266.     COPY_CHECKARGS();
  2267.     COPY_CHECKNULL();
  2268.     COPY_NEW(LispValue);
  2269.     
  2270.     /* ----------------
  2271.      *    copy node superclass fields
  2272.      * ----------------
  2273.      */
  2274.     CopyNodeFields(from, newnode, alloc);
  2275.  
  2276.     /* ----------------
  2277.      *    copy remainder of node
  2278.      * ----------------
  2279.      */
  2280.     elog(NOTICE, "_copyLispValue: LispValue - assuming LispList");
  2281.     Node_Copy(from, newnode, alloc, val.car);
  2282.     Node_Copy(from, newnode, alloc, cdr);
  2283.  
  2284.     (*to) = newnode;
  2285.     return true;
  2286. }
  2287.  
  2288. /* ----------------
  2289.  *    _copyLispSymbol
  2290.  * ----------------
  2291.  */
  2292. bool
  2293. _copyLispSymbol(from, to, alloc)
  2294.     LispValue    from;
  2295.     LispValue    *to;
  2296.     char *    (*alloc)();
  2297. {
  2298.     LispValue    newnode;
  2299.  
  2300.     COPY_CHECKARGS();
  2301.     COPY_CHECKNULL();
  2302.     COPY_NEW(LispValue);
  2303.     
  2304.     /* ----------------
  2305.      *    copy node superclass fields
  2306.      * ----------------
  2307.      */
  2308.     CopyNodeFields(from, newnode, alloc);
  2309.  
  2310.     /* ----------------
  2311.      *    copy remainder of node
  2312.      * ----------------
  2313.      */
  2314.     newnode->val.name = from->val.name;
  2315.     newnode->cdr = LispNil;
  2316.     
  2317.     (*to) = newnode;
  2318.     return true;
  2319. }
  2320.  
  2321. /* ----------------
  2322.  *    _copyLispStr
  2323.  * ----------------
  2324.  */
  2325. bool
  2326. _copyLispStr(from, to, alloc)
  2327.     LispValue    from;
  2328.     LispValue    *to;
  2329.     char *    (*alloc)();
  2330. {
  2331.     LispValue    newnode;
  2332.  
  2333.     COPY_CHECKARGS();
  2334.     COPY_CHECKNULL();
  2335.     COPY_NEW(LispValue);
  2336.     
  2337.     /* ----------------
  2338.      *    copy node superclass fields
  2339.      * ----------------
  2340.      */
  2341.     CopyNodeFields(from, newnode, alloc);
  2342.  
  2343.     /* ----------------
  2344.      *    copy remainder of node
  2345.      * ----------------
  2346.      */
  2347.     if (from->val.name != NULL)
  2348.     newnode->val.name = (char *)
  2349.         strcpy((char *) COPYALLOC(strlen(from->val.name)+1),
  2350.            from->val.name);
  2351.     else
  2352.     newnode->val.name = NULL;
  2353.     
  2354.     newnode->cdr = LispNil;
  2355.     
  2356.     (*to) = newnode;
  2357.     return true;
  2358. }
  2359.  
  2360. /* ----------------
  2361.  *    _copyLispInt
  2362.  * ----------------
  2363.  */
  2364. bool
  2365. _copyLispInt(from, to, alloc)
  2366.     LispValue    from;
  2367.     LispValue    *to;
  2368.     char *    (*alloc)();
  2369. {
  2370.     LispValue    newnode;
  2371.  
  2372.     COPY_CHECKARGS();
  2373.     COPY_CHECKNULL();
  2374.     COPY_NEW(LispValue);
  2375.     
  2376.     /* ----------------
  2377.      *    copy node superclass fields
  2378.      * ----------------
  2379.      */
  2380.     CopyNodeFields(from, newnode, alloc);
  2381.  
  2382.     /* ----------------
  2383.      *    copy remainder of node
  2384.      * ----------------
  2385.      */
  2386.     newnode->val.fixnum = from->val.fixnum;
  2387.     newnode->cdr = LispNil;
  2388.     
  2389.     (*to) = newnode;
  2390.     return true;
  2391. }
  2392.  
  2393. /* ----------------
  2394.  *    _copyLispFloat
  2395.  * ----------------
  2396.  */
  2397. bool
  2398. _copyLispFloat(from, to, alloc)
  2399.     LispValue    from;
  2400.     LispValue    *to;
  2401.     char *    (*alloc)();
  2402. {
  2403.     LispValue    newnode;
  2404.  
  2405.     COPY_CHECKARGS();
  2406.     COPY_CHECKNULL();
  2407.     COPY_NEW(LispValue);
  2408.     
  2409.     /* ----------------
  2410.      *    copy node superclass fields
  2411.      * ----------------
  2412.      */
  2413.     CopyNodeFields(from, newnode, alloc);
  2414.  
  2415.     /* ----------------
  2416.      *    copy remainder of node
  2417.      * ----------------
  2418.      */
  2419.     newnode->val.flonum = from->val.flonum;
  2420.     newnode->cdr = LispNil;
  2421.     
  2422.     (*to) = newnode;
  2423.     return true;
  2424. }
  2425.  
  2426. /* ----------------
  2427.  *    _copyLispVector
  2428.  * ----------------
  2429.  */
  2430. bool
  2431. _copyLispVector(from, to, alloc)
  2432.     LispValue    from;
  2433.     LispValue    *to;
  2434.     char *    (*alloc)();
  2435. {
  2436.     LispValue    newnode;
  2437.  
  2438.     COPY_CHECKARGS();
  2439.     COPY_CHECKNULL();
  2440.     COPY_NEW(LispValue);
  2441.     
  2442.     /* ----------------
  2443.      *    copy node superclass fields
  2444.      * ----------------
  2445.      */
  2446.     CopyNodeFields(from, newnode, alloc);
  2447.  
  2448.     /* ----------------
  2449.      *    copy remainder of node
  2450.      * ----------------
  2451.      */
  2452.     if (from->val.veci == NULL)
  2453.     newnode->val.veci = NULL;
  2454.     else {
  2455.     /* ----------------
  2456.      *  XXX am unsure about meaning of "size" field of vectori
  2457.      *  structure: is it the size of the data array or the size
  2458.      *  of the whole structure.  The code below will work in
  2459.      *  either case -- the worst that will happen is we'll waste
  2460.      *  a few bytes. -cim 4/30/90
  2461.      * ----------------
  2462.      */
  2463.     newnode->val.veci = (struct vectori *)
  2464.         COPYALLOC(sizeof(struct vectori) + from->val.veci->size);
  2465.     newnode->val.veci->size = from->val.veci->size;
  2466.     bcopy(from->val.veci->data,
  2467.           newnode->val.veci->data,
  2468.           from->val.veci->size);
  2469.     } 
  2470.     newnode->cdr = LispNil;
  2471.     
  2472.     (*to) = newnode;
  2473.     return true;
  2474. }
  2475.  
  2476. /* ----------------
  2477.  *    _copyLispList
  2478.  * ----------------
  2479.  */
  2480. bool
  2481. _copyLispList(from, to, alloc)
  2482.     LispValue    from;
  2483.     LispValue    *to;
  2484.     char *    (*alloc)();
  2485. {
  2486.     LispValue    newnode;
  2487.  
  2488.     COPY_CHECKARGS();
  2489.     COPY_CHECKNULL();
  2490.     COPY_NEW(LispValue);
  2491.     
  2492.     /* ----------------
  2493.      *    copy node superclass fields
  2494.      * ----------------
  2495.      */
  2496.     CopyNodeFields(from, newnode, alloc);
  2497.  
  2498.     /* ----------------
  2499.      *    copy remainder of node
  2500.      * ----------------
  2501.      */
  2502.     Node_Copy(from, newnode, alloc, val.car);
  2503.     Node_Copy(from, newnode, alloc, cdr);
  2504.     
  2505.     (*to) = newnode;
  2506.     return true;
  2507. }
  2508.